package com.htandroid.htandroid.webservice;

import com.htandroid.htandroid.entity.UffjqgdList_detail;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class abXMLCgglqgdlist {

    /**
     * 解析评论xml信息
     *
     * @param content
     * @return
     */
    public static ArrayList<UffjqgdList_detail> paraseCommentInfors(String content) {
        List<String> list = new ArrayList<String>();
        content = content.replace("UffjqgdList_detail=anyType", "#=#");
        String[] strs = content.split("#=");
        for (int i = 0; i < strs.length; i++) {
            if (strs[i].contains("#")) {
                list.add(strs[i].replace("#", "").trim().replace(" ", ""));
            }
        }
        ArrayList<UffjqgdList_detail> qgdlist_detail = new ArrayList<UffjqgdList_detail>();
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                list.set(i, list.get(i).replace(";};};}", "\"}"));
            }
            list.set(i, list.get(i).replace(";};", "\"}").replace("=", "\":\"").replace(";", "\",\"").replace("{avgiprice1", "{\"avgiprice1"));
            try {
                UffjqgdList_detail info = new UffjqgdList_detail();
                JSONObject dataJson = new JSONObject(list.get(i));
                info.setCvouchid(string2null(dataJson.getString("cvouchid")));
                info.setCinvcode(string2null(dataJson.getString("cinvcode")));
                info.setCinvname(string2null(dataJson.getString("cinvname")));
                info.setCinvstd(string2null(dataJson.getString("cinvstd")));
                info.setCinvm_unit(string2null(dataJson.getString("cinvm_unit")));
                info.setCinva_unit(string2null(dataJson.getString("cinva_unit")));
                info.setIinvexchrate(string2null(dataJson.getString("iinvexchrate")));
                info.setBinvtype(string2null(dataJson.getString("binvtype")));
                info.setCinvaddcode(string2null(dataJson.getString("cinvaddcode")));
                info.setDdate_dh(string2null(dataJson.getString("ddate_dh")));
                info.setInum(string2null(dataJson.getString("inum")));
                info.setIsnum(string2null(dataJson.getString("isnum")));
                info.setIquantity(string2null(dataJson.getString("iquantity")));
                info.setIqgq(string2null(dataJson.getString("iqgq")));
                info.setIprice(string2null(dataJson.getString("iprice")));
                info.setIamount(string2null(dataJson.getString("iamount")));
                info.setCvencodep1(string2null(dataJson.getString("cvencodep1")));
                info.setCvennamep1(string2null(dataJson.getString("cvennamep1")));
                info.setCvencodep2(string2null(dataJson.getString("cvencodep2")));
                info.setCvennamep2(string2null(dataJson.getString("cvennamep2")));
                info.setCvencodep3(string2null(dataJson.getString("cvencodep3")));
                info.setCvennamep3(string2null(dataJson.getString("cvennamep3")));
                info.setIpricep1(string2null(dataJson.getString("ipricep1")));
                info.setIpricep2(string2null(dataJson.getString("ipricep2")));
                info.setIpricep3(string2null(dataJson.getString("ipricep3")));
                info.setCchecker(string2null(dataJson.getString("cchecker")));
                info.setCcheckdate(string2null(dataJson.getString("ccheckdate")));
                info.setCdisapprovereason(string2null(dataJson.getString("cdisapprovereason")));
                info.setCvencode(string2null(dataJson.getString("cvencode")));
                info.setCvenname(string2null(dataJson.getString("cvenname")));
                info.setCdefine1(string2null(dataJson.getString("cdefine1")));
                info.setCdefine2(string2null(dataJson.getString("cdefine2")));
                info.setCdefine3(string2null(dataJson.getString("cdefine3")));
                info.setIinvsprice(string2null(dataJson.getString("iinvsprice")));
                info.setCdefine4(string2null(dataJson.getString("cdefine4")));
                info.setBapprove(string2null(dataJson.getString("bapprove")));
                info.setQgdsid(string2null(dataJson.getString("qgdsid")));
                info.setInorder(string2null(dataJson.getString("inorder")));
                info.setBclose(string2null(dataJson.getString("bclose")));
                info.setDjtype(string2null(dataJson.getString("djtype")));
                info.setDjcvencode(string2null(dataJson.getString("djcvencode")));
                info.setDjprice(string2null(dataJson.getString("djprice")));
                info.setCanupdjxy(string2null(dataJson.getString("canupdjxy")));
                info.setSuccount(string2null(dataJson.getString("succount")));
                info.setDdate(string2null(dataJson.getString("ddate")));
                info.setIlprice(string2null(dataJson.getString("ilprice")));
                info.setClvencode(string2null(dataJson.getString("clvencode")));
                info.setIlquantity(string2null(dataJson.getString("ilquantity")));
                info.setAvgiquantity(string2null(dataJson.getString("avgiquantity")));
                info.setCvencode1(string2null(dataJson.getString("cvencode1")));
                info.setAvgiprice1(string2null(dataJson.getString("avgiprice1")));
                info.setCvencode2(string2null(dataJson.getString("cvencode2")));
                info.setAvgiprice2(string2null(dataJson.getString("avgiprice2")));
                info.setCchangedate(string2null(dataJson.getString("cchangedate")));
                info.setCdepcode(string2null(dataJson.getString("cdepcode")));
                info.setCnocheckreason(string2null(dataJson.getString("cnocheckreason")));
                info.setCqgtype(string2null(dataJson.getString("cqgtype")));
                info.setCvouchnum(string2null(dataJson.getString("cvouchnum")));
                info.setIfrequency(string2null(dataJson.getString("ifrequency")));
                info.setPrecchecker(string2null(dataJson.getString("precchecker")));
                info.setS_cdefine1(string2null(dataJson.getString("s_cdefine1")));
                info.setS_cdefine2(string2null(dataJson.getString("s_cdefine2")));
                info.setS_cdefine3(string2null(dataJson.getString("s_cdefine3")));
                info.setS_cdefine4(string2null(dataJson.getString("s_cdefine4")));
                info.setS_id(string2null(dataJson.getString("s_id")));
                info.setVenplatid(string2null(dataJson.getString("venplatid")));
                info.setCdepname(string2null(dataJson.getString("cdepname")));
                qgdlist_detail.add(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return qgdlist_detail;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
